import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/tap_mask/tap_mask.dart';

/// 按钮
class ChooseButton extends StatelessWidget {
  final String text;
  final Color color;
  final Function? onTap;

  ChooseButton({
    required this.text,
    this.color = Colors.black,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return TapMask(
      onTap: () {
        if (onTap != null) {
          onTap!();
        }
      },
      child: Container(
        height: 60,
        color: Colors.white,
        alignment: Alignment.center,
        child: Text(
          text,
          style: TextStyle(
            fontWeight: FontWeight.bold,
            color: color,
          ),
        ),
      ),
    );
  }
}

Future<T?> showChooseBottomSheet<T>({
  required BuildContext context,
  List<ChooseButton> sheets = const [],
}) {
  return showModalBottomSheet<T?>(
    context: context,
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
    builder: (BuildContext context) {
      return Container(
        alignment: Alignment.bottomCenter,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // 占位
            Expanded(
              flex: 1,
              child: GestureDetector(
                onTap: () => Navigator.pop(context),
              ),
            ),
            // 内容
            ClipRRect(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20),
                topRight: Radius.circular(20),
              ),
              child: Container(
                color: Colors.white,
                child: Column(
                  children: [
                    ...List.generate(sheets.length, (index) {
                      return Column(
                        children: [
                          sheets[index],
                          index < sheets.length - 1
                              ? Divider(
                                  height: 1,
                                )
                              : SizedBox(),
                        ],
                      );
                    }),
                    Divider(
                      height: 10,
                      thickness: 10,
                      color: Colors.grey[100],
                    ),
                    ChooseButton(
                      text: '取消',
                      color: Colors.red,
                      onTap: () {
                        Navigator.pop(context, null);
                      },
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}
